import java.util.Arrays;
import java.util.HashMap;

public class SumArray {
    public static  int subarraySum(int[] nums, int k) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            int sum = nums[i];
            if (sum ==k){
                count++;
            }
            for (int j = i+1; j < nums.length; j++) {
                sum += nums[j];
                if (sum==k){
                    count++;
                }
            }
        }
        return count++;
    }

    public static  int subarraySum2(int[] nums, int k) {
        int count = 0, pre = 0;
        HashMap < Integer, Integer > mp = new HashMap < > ();
        mp.put(0, 1);
        for (int i = 0; i < nums.length; i++) {
            pre += nums[i];
            if (mp.containsKey(pre - k)) {
                count += mp.get(pre - k);
            }
            mp.put(pre, mp.getOrDefault(pre, 0) + 1);
        }
        return count;
    }

    public static void main(String[] args) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        System.out.println(hashMap.get(1));
    }

}
